package beauty;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by Robo on 2018/1/18.
 */
public class SortNumber {
    private static int count = 0;

    public static void main(String[] args) {
        int n = 9;
//        String str = RandomUtil.randomIntStr(3);
        String str = "125";
        char[] charArray = str.toCharArray();
        System.out.println(str);
//        char[] reverseArr = reverse2(charArray,3);
//        System.out.println(String.valueOf(reverseArr));
        int index = 0 , dealLength = charArray.length;
        for (; dealLength > 1 ; dealLength--) {
            sortOne(charArray, index, dealLength);
        }
//        dealLength = charArray.length-1;

//        charArray = Arrays.copyOf(charArray, 8);
       /* for (int i = 0; i < charArray.length; i++) {
            int i1 = Integer.parseInt(String.valueOf(charArray[i]));
            for (int j = i+1; j < charArray.length; j++) {
                int j1 = Integer.parseInt(String.valueOf(charArray[j]));
                if (j1 < i1) {
                    charArray = reverse2(charArray, j+1);
                }
            }
        }*/
        System.out.println(String.valueOf(charArray));
        System.out.println("需要反转的次数:"+count);




            System.out.println("1231 ".trim());
            ArrayList<Integer> li = new ArrayList<Integer>();
            ArrayList<String> lf = new ArrayList<>();
            if (li.getClass() == lf.getClass()) // evaluates to true
                System.out.println("Equal2");


    }

    private static void sortOne(char[] charArray, int index, int dealLength) {
        for (int i = 0; i < dealLength - 1; i++) {
            if (charArray[index] < charArray[i + 1 ]) {
                index = i + 1;
            }
        }
//        System.out.println(index);
        reverse2(reverse2(charArray, index+1),dealLength);
    }

    public static char[] reverse(char[] chars) {
        int index = chars.length -1  ;
        for (int i = 0; ; i++,index--) {
            if (i >= index) {
                break;
            }char buf = chars[i];
            chars[i] = chars[index];
            chars[index] = buf;
        }
        return chars;
    }

    public static char[] reverse2(char[] chars,int reverseLen) {
        char[] prefix = reverse(Arrays.copyOf(chars, reverseLen));
        for (int i = 0; i < prefix.length; i++) {
            chars[i] = prefix[i];
        }
        count++;
        return chars;
    }
    public static String swap(String str) {
        if (str.length() == 2) {
            return str.substring(1) + str.substring(0, 1);
        }else {
            return str;
        }
    }
}

